<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center personalData_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub personalData_fd0_0'>
          <view class='flex flex-wrap align-center personalData_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  personalData_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='personalData_fd0_0_c1_c0'>个人资料</text>
          </view>
          <view class='flex flex-wrap align-center justify-end personalData_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>

      <view class="flex flex-direction flex-wrap align-stretch personalData_flex_1">
        <view class='flex flex-wrap align-center personalData_fd1_0'>
          <text class='personalData_fd1_0_c0'>头像</text>
          <view class="upload position-relative personalData_fd1_0_c1">

            <image class=" personalData_fd1_0_c1_image" mode="aspectFit"
              @tap="croppingUploadImage('avatar','avatar',user,user)"
              :src="user.avatar ? user.avatar : STATIC_URL+'32.png'"></image>
          </view>
          <image class='personalData_fd1_0_c2' mode="aspectFit" :src='STATIC_URL+"33.png"'></image>
        </view>
        <view class='flex flex-wrap align-center justify-between personalData_fd1_1'>
          <text class='personalData_fd1_0_c0'>昵称</text>
          <benben-input class='flex-sub personalData_fd1_1_c1' type="text" :placeholder="`请输入昵称`" confirm-type="done"
            :maxlength="7" placeholder-style="color:#666666;font-size:32rpx" v-model="user.nickname" />
        </view>
        <view class='flex flex-wrap align-center justify-between personalData_fd1_1'
          @tap.stop="pickerDiy1706077549149=true">
          <text class='personalData_fd1_0_c0'>性别</text>
          <view class='flex flex-wrap align-center'>
            <text class='personalData_fd1_2_c1_c0' v-if="user.sex!='1' && user.sex!='2'">{{sex}}</text><text
              class='personalData_fd1_2_c1_c0' v-if="user.sex=='1'">男</text><text class='personalData_fd1_2_c1_c0'
              v-if="user.sex=='2'">女</text>
            <image class='personalData_fd1_0_c2' mode="aspectFit" :src='STATIC_URL+"33.png"'></image>
          </view>
        </view>
        <view class='flex flex-wrap align-center personalData_fd1_3'>
          <text class='personalData_fd1_3_c0'>生日</text>
          <text class='personalData_fd1_3_c1' @click.stop="pickerDiy1703520610264=true">{{user.birthday}}</text>
        </view>
        <view class='flex flex-wrap align-center justify-between personalData_fd1_1'>
          <text class='personalData_fd1_0_c0'>联系方式</text>
          <!-- <text class='personalData_fd1_4_c1'>{{user.mobile}}</text> -->
          <benben-input class='flex-sub personalData_fd1_1_c1' type="text" :placeholder="`请输入联系方式`" confirm-type="done"
            :maxlength="7" placeholder-style="color:#666666;font-size:32rpx" v-model="user._mobile" />
        </view>
        <view class='flex flex-wrap align-center personalData_fd1_5'>
          <text class='personalData_fd1_3_c0'>用户类型</text>
          <text class='personalData_fd1_3_c1'>普通用户</text>
        </view>
        <button class='personalData_fd1_6' @tap.stop="submitsFunc()">保存</button>
      </view>


      <!--选择性别开始 -->
      <benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1706077549149" :label.sync='sex'
        :value.sync='user.gender' :options='sex_options' mode='selector' :mask-show='true' :timeout='true'
        :picker-height='88' default-type='value' :default-props='{"label":"name","value":"value"}'>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between personalData_picker2_0'>
            <text class='personalData_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
            <text class='personalData_picker2_0_c1'>选择性别</text>
            <text class='personalData_picker2_0_c2' @tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确认</text>
          </view>
        </template>
      </benben-picker>
      <!--选择性别结束 -->
      <benben-picker ref="benbenWritePickerCodepicker1" :visible.sync="pickerDiy1703520610264"
        :value.sync='user.birthday' mode='date' :picker-height='88' :current='true' :mask-show='true' fields='day'
        :timeout='true' start-year='1990-01-01' end-year='现在' from-data=''>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between personalData_picker2_0'>
            <text class='personalData_picker2_0_c0'
              @tap="$refs.benbenWritePickerCodepicker1.cancel()">{{$t('取消')}}</text>
            <text>{{$t('选择生日')}}</text>
            <text class='personalData_picker2_0_c2'
              @tap="$refs.benbenWritePickerCodepicker1.pickerConfirm()">{{$t('确认')}}</text>
          </view>
        </template>
      </benben-picker>

    </view>
  </view>
</template>
<script>
  import UploadImage from '@/common/utils/upload-image.js'
  import {
    validate
  } from '@/common/utils/validate.js'

  export default {
    components: {},


    data() {
      return {
        pickerDiy1703520610264: false,
        "pickerDiy1706077549149": false,
        "header_img": "",
        "user": {
          "invite_code": "",
          "address": "",
          "address_code": "",
          "hobby": "",
          "tags": "",
          "id": "",
          "userlevel_id": "",
          "mobile": "",
          "real_name": "",
          "avatar": "",
          "account": "",
          "email": "",
          "birthday": "",
          "gender": "",
          "create_time": "",
          "user_money": "",
          "freeze_money": "",
          "total_consumption_money": "",
          "score": "",
          "_mobile": "",
          "coupon": "",
          "collection_count": "",
          "browse_count": "",
          "total_money": "",
          "certified": "",
          "nickname": "",
          "is_pay_password": "",
          "follow_count": "",
          "is_close": "",
          "lastid": "",
          "userlevel_name": ""
        },
        "sex": "",
        "sex_options": [{
          "name": "保密",
          "value": "0",
          "image": ""
        }, {
          "name": "男",
          "value": "1",
          "image": ""
        }, {
          "name": "女",
          "value": "2",
          "image": ""
        }]
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      this.queryUserInfoFunc()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //裁剪图片上传
      croppingUploadImage(id, path, obj, obj1, fnName = false) {
        let self = this
        // uni.showModal({
        //   title: '相机相册信息授权提示',
        //   content: '用户拍摄/选取内容发布，拍摄/选取图片更换头像，扫描二维码，聊天或者AR识别等功能',
        //   success(res) {
        //     if (res.confirm) {
        if (!obj) obj = this
        if (!obj1) obj1 = this
        let itemList = obj1[path] ? ['修改头像', '拍照', '从手机相册选择'] : ['拍照', '从手机相册选择']

        function imageCroppingCuccess() {
          uni.$once('image-cropping-success', (file) => {
            if (!file) return
            new UploadImage([file], {
              complete: (res) => {
                self.user.avatar = res[0].path
                if (id) self.$set(obj, id, res[0].id)
                if (path) self.$set(obj1, path, res[0].path)
                if (fnName) self[fnName]()
              },
            })
          })
        }
        uni.showActionSheet({
          itemList: itemList,
          success: function(res) {
            if (res.tapIndex == 0 && obj1[path]) {
              uni.navigateTo({
                url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&&myImgUrl=' +
                  obj1[path],
                animationDuration: 0,
              })
              imageCroppingCuccess()
            }
            if ((res.tapIndex == 1 && obj1[path]) || (res.tapIndex == 0 && !obj1[path])) {
              uni.chooseImage({
                count: 1,
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: (res) => {
                  // 跳转到图片裁切页面
                  uni.navigateTo({
                    url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
                    animationDuration: 0,
                  })
                  imageCroppingCuccess()
                },
              })
            }
            if ((res.tapIndex == 2 && obj1[path]) || (res.tapIndex == 1 && !obj1[path])) {
              uni.chooseImage({
                count: 1,
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
                success: (res) => {
                  // 跳转到图片裁切页面
                  uni.navigateTo({
                    url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
                    animationDuration: 0,
                  })
                  imageCroppingCuccess()
                },
              })
            }
          },
          fail: function(res) {
            console.log(res.errMsg)
          },
        })
        //     } else if (res.cancel) {
        //       console.log('用户点击取消');
        //     }
        //   }
        // })


      },
      //获取用户详细信息
      async queryUserInfoFunc() {
        //请求方法
        //数据验证

        let datauser = await this.$api.get(global.apiUrls.post5c78c4772da97, {

        });

        if (datauser.data.code != 1) {
          this.$message.info(datauser.data.msg);
          return
        }
        let infouser = datauser.data;
        this.user = infouser.data

        if (this.user.gender == 0) {
          this.sex = '保密';
        } else if (this.user.gender == '1') {
          this.sex = '男';
        } else if (this.user.gender == '2') {
          this.sex = ' 女';
        }
      },
      //修改个人资料
      async submitsFunc() {
        //请求方法
        //数据验证

        let data5cb54af125f1c = await this.$api.dbPost(global.apiUrls.post5cb54af125f1c, {
          avatar: this.user.avatar,
          nickname: this.user.nickname,
          gender: this.user.gender
        });
        if (!data5cb54af125f1c) return
        if (data5cb54af125f1c.data.code != 1) {
          this.$message.info(data5cb54af125f1c.data.msg);
          return
        }



        this.$message.info('修改成功');
        this.$urouter.navigateBack(1);
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .personalData_flex_0 {
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .personalData_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333;
    line-height: 88rpx;
  }

  .personalData_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .personalData_fd0_0_c0 {
    width: 120rpx;
  }

  .personalData_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .personalData_flex_1 {
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .personalData_fd1_6 {
    background: rgba(16, 51, 126, 1);
    border-radius: 44rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor3);
    line-height: 88rpx;
    height: 88rpx;
    margin: 45rpx 0rpx 45rpx 0rpx;
    position: absolute;
    width: 686rpx;
    bottom: 0rpx;
  }

  .personalData_fd1_5 {
    background: #fff;
    background-size: 100% auto !important;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .personalData_fd1_4_c1 {
    color: rgba(102, 102, 102, 1);
    font-size: 32rpx;
    font-weight: 400;
    line-height: 45rpx;
  }

  .personalData_fd1_3_c1 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 40rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .personalData_fd1_3_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 40rpx;
  }

  .personalData_fd1_3 {
    border-bottom: 1px solid var(--benbenbdColor0);
    background: #fff;
    background-size: 100% auto !important;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .personalData_fd1_2_c1_c0 {
    color: var(--benbenFontColor1);
    font-size: 32rpx;
    text-align: right;
  }

  .personalData_fd1_1_c1 {
    text-align: right;
    font-size: 32rpx;
    font-weight: 400;
    color: rgba(51, 51, 51, 1);
    margin: 0rpx 0rpx 0rpx 24rpx;
  }

  .personalData_fd1_1 {
    border-bottom: 1px solid var(--benbenbdColor0);
    height: 125rpx;
  }

  .personalData_fd1_0_c2 {
    width: 22rpx;
    height: 32rpx;
    margin: 0rpx 0rpx 0rpx 16rpx;
  }

  .personalData_fd1_0_c1_image {
    width: 96rpx;
    height: 96rpx;
    border-radius: 48rpx;
  }

  .personalData_fd1_0_c1 {
    width: 100rpx;
    height: 100rpx;
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .personalData_fd1_0_c0 {
    font-size: 32rpx;
    font-weight: 400;
    color: #333333;
    line-height: 45rpx;
  }

  .personalData_fd1_0 {
    border-bottom: 1px solid var(--benbenbdColor0);
    height: 152rpx;
  }

  .personalData_picker2_0_c2 {
    color: var(--benbenFontColor6);
    font-size: 28rpx;
  }

  .personalData_picker2_0_c1 {
    font-size: 32rpx;
    color: var(--benbenFontColor1);
  }

  .personalData_picker2_0_c0 {
    font-size: 28rpx;
    color: var(--benbenFontColor2);
  }

  .personalData_picker2_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
    border-radius: 25rpx 25rpx 0rpx 0rpx;
    background-size: 100% auto !important;
  }
</style>
